import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '科室',			name: 'parent_project_id', 	type: 'select', loading:true, idStr:'uuid' },
			{ label: '岗位',			name: 'project_id', 		type: 'select', loading:true },
			{ label: '标本条码',		name: 'spec_code' },
			{ label: '接收时间',		names: ['start_at','end_at'], type:'date-range',format:1 },
		],
	}
	
	model = {}
	query = {operation_type: 6}
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
		
		$fn.fresh.on(this.fetch)
	}
	
	componentWillUnmount(){
		$fn.fresh.remove()
	}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow( forms, 'parent_project_id', await f.getCache({ api:'ke_shi' }) )
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' }) )
			// 
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/getUserBehaviorLists')
	
	// 表单
	cols = [
		{ title: '条码号', 		dataIndex: 'spec_code', 			...$fn.table.spec_code },
		{ title: '实验号', 		dataIndex: 'experiment_num', 		...$fn.table.exp_num },
		{ title: '姓名', 		dataIndex: 'patient_name', 			...$fn.table.name },
		{ title: '性别', 		dataIndex: 'sex', 					...$fn.table.sex },
		{ title: '年龄', 		dataIndex: 'age', 					...$fn.table.age },
		{ title: '接收时间', 	dataIndex: 'check_time', 			...$fn.table.time },
		{ title: '医院名称', 	dataIndex: 'hosp_name', 			width:250 },
		{ title: '检验科室', 	dataIndex: 'parent_project_name', 	width:150 },
		{ title: '检验岗位', 	dataIndex: 'project_name', 			width:150 },
		{ title: '原因', 		dataIndex: 'operation_reason', 		width:200 },
		{ title: '创建时间', 	dataIndex: 'created_at', 			...$fn.table.time },
		{ title: '操作时间', 	dataIndex: 'updated_at', 			...$fn.table.time },
		{ title: '操作人', 		dataIndex: 'operator_name', 		width:80 },
		TableControls.controls.call(this, { width: 190 })
	]
	// 表格操作按钮
	table_controls = ( text, { spec_num, spec_code, operation_source }) => {
		return [		
			TableControls.pushTo.call(this, '修改资料', `patient-detail?spec_code=${spec_code}&page_source=kf`),
			+spec_num.length !== 0 && TableControls.pushTo.call(this, '预览报告单', `preview-report?spec_num=${spec_num}&spec_code=${spec_code}`)
		]
	}
	render(){
		return (
			<Page title='客户迟发记录'>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this, { isInit: window.isInit })}
			</Page>
		)
	}
}

export default Index